#include "fileinfo.h"
#include "ui_fileinfo.h"

FileInfo::FileInfo(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::FileInfo)
{
    ui->setupUi(this);
    setWindowTitle("文件信息");
}

FileInfo::~FileInfo()
{
    delete ui;
}

void FileInfo::getFileInfo(QString &fileName)
{
    QFileInfo info(fileName);      //该类可以获取文件的信息
    qint64 size=info.size();         //文件大小
    QDateTime createTime=info.created();      //文件创建时间
    QDateTime lastMTime=info.lastModified();  //文件最近修改时间
    QDateTime lastRTime=info.lastRead();      //文件最近访问时间

    //文件的属性信息
    bool bIsDir=info.isDir();
    bool bIsFile=info.isFile();
    bool bIsSymLink=info.isSymLink();
    bool bIsHidden=info.isHidden();
    bool bIsWritable=info.isWritable();
    bool bIsReadable=info.isReadable();
    bool bIsExcutable=info.isExecutable();


    ui->fileSizeLineEdit->setText(QString::number(size));
    ui->fileCreateLineEdit->setText(createTime.toString());
    ui->fileModifyLineEdit->setText(lastMTime.toString());
    ui->fileReadLineEdit->setText(lastRTime.toString());

    ui->isDirCheckBox->setChecked(bIsDir);
    ui->isFileCheckBox->setChecked(bIsFile);
    ui->isSymLinkCheckBox->setChecked(bIsSymLink);
    ui->isHiddenCheckBox->setChecked(bIsHidden);
    ui->isWritableCheckBox->setChecked(bIsWritable);
    ui->isReadableCheckBox->setChecked(bIsReadable);
    ui->isExecutableCheckBox->setChecked(bIsExcutable);


}

void FileInfo::on_browseFileBtn_clicked()
{
    //返回文件的路径
    QString fileName=QFileDialog::getOpenFileName(this,           //指定当前窗口为父窗口
                                                  "打开文件",
                                                  ".",
                                                  "files(*)");     //可以选择所有类型


   // QString path=QFileDialog::getExistingDirectory(this,"选择目录",".");

    ui->fileNameLineEdit->setText(fileName);
    getFileInfo((fileName));
}
